package von.seiji.cn.test;

import cn.hutool.core.io.FileUtil;
import org.junit.Test;
import java.io.File;
import java.util.Arrays;
import java.util.Date;

/**
 * @Author:Seiji
 * @Time:2020/12/6 16:48
 */
public class T4 {
    String json = "{\"code\": 1, \"image\": \"/9j/4AAQSkZJRgABAQAAAQABAAD\",\"code1\":\"1\" }";
   // JSONObject jsonObject;

  /*  @Test
    public void test09() throws JSONException {
        JSONObject jsonObject = new JSONObject(json);
        System.out.println(jsonObject.getInt("code1"));
    }

    @Test
    public void test1() {
        try {
            jsonObject = new JSONObject(json);
            System.out.println("jsonObject = " + jsonObject);
            System.out.println("jsonObject.getString(\"image\") = " + jsonObject.getString("image"));
            boolean image1 = jsonObject.has("image1");
            System.out.println("image1 = " + image1);
            String image11 = jsonObject.getString("image1");
            System.out.println("image11 = " + image11);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }*/

    @Test
    public void test02(){
        Date date = new Date();
        String format = String.format("%tc", date);
        System.out.println("format = " + format);
        System.out.println("date = " + date);
        String s = String.format("%tF1$ %tT1$", date);
        System.out.println("s = " + s);
    }

    @Test
    public void test03(){
        StringBuilder hello = new StringBuilder("hello");
         hello.insert(4, "world");
        System.out.println("hello = " + hello);
        boolean af = "dsafds".contains("af");
        System.out.println("af = " + af);
        StringBuilder world = hello.delete(4, 9).append("world");
        System.out.println(world.toString());
        StringBuilder replace = world.replace(4, 5, "0");
        System.out.println("replace = " + replace);
    }
    @Test
    public void test04(){
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(String.format("%d*%d=%d\t",j,i,i*j));
            }
            System.out.println();
        }
    }
    @Test
    public void test05(){
        int num=1000;
        System.out.printf("add(%d) = " + add(num),num);
    }

    //给定一个num,计算从1加到num的和
    public int add(int num){
            return 1==num?num:num+add(num-1);
    }

    @Test
    public void test06(){
      //  ImageIO.write()
        int[] ints = {5, 23, 8, 2, 54, -90, 23};
        Arrays.sort(ints);
        System.out.println("ints = " + Arrays.toString(ints));
    }

    @Test
    public void test07(){
        int[] ints = {5, 23, 8, 2, 54, -90, 23};
        sort(ints);
        System.out.println(Arrays.toString(ints));
    }

    public void sort(int [] a){
        sort(a,0,a.length-1);
    }

    public void sort(int [] a,int left,int right){
        for (int i = left, j = i; i < right; j = ++i) {
            int ai = a[i + 1];
            while (ai < a[j]) {
                a[j + 1] = a[j];
                if (j-- == left) {
                    break;
                }
            }
            a[j + 1] = ai;
        }
    }

    public void desort(int[] a, int left, int right){
        for(int i= left, j = i; i< right; j = ++i){
            int ai = a [i + 1];
            while (ai > a[j]){
                a[j + 1] = a[j];
                if(j-- == left){
                    break;
                }
            }
            a[j + 1] = ai;
        }
    }


    @Test
    public void test071(){
        int i=2;
        System.out.println(i-- == 2);
        System.out.println("i = " + i);
    }

    @Test
    public void test08(){
        int[] ints = {4, 25, 10};
        Arrays.sort(ints);//4,10,25
        int i = Arrays.binarySearch(ints, 12);
        System.out.println("i = " + i);
    }

    @Test
    public void test144() {

        File file = new File("C:\\Users\\Administrator\\AppData\\Roaming\\360Safe\\DesktopRest\\eye\\bk_image");
        File[] files = file.listFiles();
        for (File file1 : files) {
            file1.renameTo(new File(file, FileUtil.getName(file1.getName())+".jpg"));
        }
        System.out.println("完成");
    }

    @Test
    public void test157() {
        short a =4;
       // a = a + 1;
        a+=3;
        System.out.println(--a > 3);
    }

    @Test
    public void test165() {
        System.out.println(8^3);
        System.out.println(238^3);
        System.out.println(8^768673);
        System.out.println(8^-3);
        System.out.println(-435348^3);
    }

  /*  @Test
    public void test174() {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        String IMAGE_PATH = "F://1.jpg";
        System.out.println(new File(IMAGE_PATH).exists());
        System.out.println(new File(IMAGE_PATH).length());
        Mat imread = Imgcodecs.imread(IMAGE_PATH);
        System.out.println(JSON.toJSONString(imread));
        //rectangle(Mat,点1,点2,线条颜色)
        Imgproc.rectangle(imread, new Point(10, 10), new Point(200, 200), new Scalar(0, 255, 0));
        HighGui.imshow("白蛇", imread);*/
     /*   int i = HighGui.waitKey(0);
        System.out.println("用户输入的键值："+i);
        if(i == 27){
            System.out.println("关闭了");
          //  HighGui.destroyWindow("白蛇");
        }

    }*/
//-Djava.library.path=E:\Seiji926\software\OpenVC\opencv440\build\java\x64
    @Test
    public void test195() {
        String property = System.getProperty("java.library.path");
        Arrays.asList(property.split(";")).forEach(item -> {
            System.out.println(item);
            System.out.println(new File(item).exists());
        });
    }




}
